import os
import subprocess,shlex

path1_0 = "E:\\company_project\\e6_project\\baixingyaofang\\1.0"
path3_0 = "E:\\company_project\\e6_project\\baixingyaofang\\3.0"


def list_path(filepath):
    # 遍历filepath下所有文件，包括子目录
    files = os.listdir(filepath)
    path_list = []
    for fi in files:
        fi_d = os.path.join(filepath, fi)
        if not os.path.isdir(fi_d):
            continue
        # print(os.path.join(filepath, fi_d))
        path_list.append(fi)
    return path_list


def pull(parent_path, paths):
    for path in paths:
        os.chdir(os.path.join(parent_path, path))
        print(os.path.join(parent_path, path))
        command = shlex.split('cd %s' % path)
        step1 = subprocess.Popen(command)
        step1.wait()
        command = shlex.split('git pull')
        step2 = subprocess.Popen(command)
        step2.wait()
        command = shlex.split('cd ..')
        step3 = subprocess.Popen(command)
        step3.wait()


def main():
    path_list = list_path(path1_0)
    # print(path1_0, path_list)
    pull(path1_0, path_list)


if __name__ == '__main__':
    main()
